﻿using System;
using System.Reflection;

namespace Gaea.CodeFirst
{
    public class CreateTableBasic
    {
        public string BasicCreateTable(OperateTableContext operateTableContext)
        {
            PropertyInfo[] propertyInfo = operateTableContext.typeOfGaeaSon.GetProperties();
            string ColumnSql = "";
            foreach (var property in propertyInfo)
            {
                var column_name = property.Name;
                var column_type = property.PropertyType.Name;

                var attributes = property.GetCustomAttributes();

                ConvertType convertType = new ConvertType();

                if (operateTableContext.DbName == EnumDbName.MySql)
                {
                    column_type = convertType.ConvertMySqlType(attributes, column_type);
                }
                else if (operateTableContext.DbName == EnumDbName.SqlServer)
                {
                    column_type = convertType.ConvertSqlServerType(attributes, column_type);
                }
                else if (operateTableContext.DbName == EnumDbName.Oracle)
                {
                    column_type = convertType.ConvertOracleType(attributes, column_type);
                }

                ColumnSql += column_name + " " + column_type + " not null,";
            }

            ColumnSql = ColumnSql.TrimEnd(',');

             return ColumnSql;
        }
    }
}
